﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;

namespace ParticleEditor
{
    class Emitter
    {
        public void Update(double dt)
        {
            foreach (Particle p in LiveParticles)
            {
                p.Update(dt);
            }

        }

        public void SpawnParticles(decimal numParticles, decimal minLife, decimal maxLife,
                                  decimal minPosX, decimal maxPosX, decimal minPosY, decimal maxPosY,
                                   decimal minVelX, decimal maxVelX, decimal minVelY, decimal maxVelY)
        {
            Random rand = new Random();
            for (int i = 0; i < numParticles; ++i)
            {
                //if Rect then
                decimal posX = rand.Next((int)minPosX,(int)maxPosX);
                decimal posY = rand.Next((int)minPosY, (int)maxPosY);
                //if Circle then
                //........
                //if line then
                //........
                //end of emitter shape


                decimal velX = rand.Next((int)minVelX, (int)maxVelX);
                decimal velY = rand.Next((int)minVelY, (int)maxVelY);

                decimal life = rand.Next((int)minLife, (int)maxLife);

                AddParticle(life, posX, posY, velX, velY);
            }
        }


        private void AddParticle(decimal life, decimal posX, decimal posY, decimal velX, decimal velY)
        {
            LiveParticles.Add(new Particle(life, posX, posY, velX, velY));
        }






        public void ResetAllParticles()
        {
            LiveParticles.Clear();
            DeadParticles.Clear();
        }

        private decimal positionX = 50;

        public decimal PositionX
        {
            get { return positionX; }
            set { positionX = value; }
        }
        private decimal positionY = 50;

        public decimal PositionY
        {
            get { return positionY; }
            set { positionY = value; }
        }
        private decimal gravityX = 0;

        public decimal GravityX
        {
            get { return gravityX; }
            set { gravityX = value; }
        }
        private decimal gravityY = 0;

        public decimal GravityY
        {
            get { return gravityY; }
            set { gravityY = value; }
        }
        private decimal spawnRate = 10;//(particles per frame added to live list)

        public decimal SpawnRate
        {
            get { return spawnRate; }
            set { spawnRate = value; }
        }
        private decimal maxParticles = 300;//(total particles)

        public decimal MaxParticles
        {
            get { return maxParticles; }
            set { maxParticles = value; }
        }
        private decimal minLifetime = 1000;

        public decimal MinLifetime
        {
            get { return minLifetime; }
            set { minLifetime = value; }
        }
        private decimal maxLifetime = 1000;

        public decimal MaxLifetime
        {
            get { return maxLifetime; }
            set { maxLifetime = value; }
        }
        private decimal minScaleX = 1;//(0+)

        public decimal MinScaleX
        {
            get { return minScaleX; }
            set { minScaleX = value; }
        }
        private decimal maxScaleX = 1;

        public decimal MaxScaleX
        {
            get { return maxScaleX; }
            set { maxScaleX = value; }
        }
        private decimal minScaleY = 1;//(0+)

        public decimal MinScaleY
        {
            get { return minScaleY; }
            set { minScaleY = value; }
        }
        private decimal maxScaleY = 1;

        public decimal MaxScaleY
        {
            get { return maxScaleY; }
            set { maxScaleY = value; }
        }
        private decimal minVelocityX = 0;

        public decimal MinVelocityX
        {
            get { return minVelocityX; }
            set { minVelocityX = value; }
        }
        private decimal maxVelocityX = 0;

        public decimal MaxVelocityX
        {
            get { return maxVelocityX; }
            set { maxVelocityX = value; }
        }
        private decimal minVelocityY = 0;

        public decimal MinVelocityY
        {
            get { return minVelocityY; }
            set { minVelocityY = value; }
        }
        private decimal maxVelocityY = 0;

        public decimal MaxVelocityY
        {
            get { return maxVelocityY; }
            set { maxVelocityY = value; }
        }
        private decimal startRotation = 0;

        public decimal StartRotation
        {
            get { return startRotation; }
            set { startRotation = value; }
        }
        private decimal endRotation = 0;

        public decimal EndRotation
        {
            get { return endRotation; }
            set { endRotation = value; }
        }

        private Color startColor = Color.WhiteSmoke;

        public Color StartColor
        {
            get { return startColor; }
            set { startColor = value; }
        }
        public Color endColor = Color.DarkRed;

        private List<Particle> liveParticles = new List<Particle>();

        public List<Particle> LiveParticles
        {
            get { return liveParticles; }
            set { liveParticles = value; }
        }
        private List<Particle> deadParticles = new List<Particle>();

        public List<Particle> DeadParticles
        {
            get { return deadParticles; }
            set { deadParticles = value; }
        }

        private bool looping = true;

        public bool Looping
        {
            get { return looping; }
            set { looping = value; }
        }

        private Image particleImage = Resources.Resource1._default;

        public Image ParticleImage
        {
            get { return particleImage; }
            set { particleImage = value; }
        }

    }
}
